<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let loginList = [
        { userName: 'admin', password: 'admin321' },
        { userName: 'zhangsan', password: 'zs321' },
        { userName: 'lisi', password: 'ls321' },
        { userName: 'yyqx', password: 'yyqx321' },
      ]
      let userInfo = {
        token1: {
          city: '杭州',
          money: '1000w',
          sex: '女',
          userName: 'admin',
          password: 'admin321',
        },
        token2: {
          city: '北京',
          money: '1100w',
          sex: '女',
          userName: 'zhangsan',
          password: 'zs321',
        },
        token3: {
          city: '北京',
          money: '800w',
          sex: '男',
          userName: 'lisi',
          password: 'ls321',
        },
        token4: {
          city: '天津',
          money: '600w',
          sex: '男',
          userName: 'yyqx',
          password: 'yyqx321',
        },
      }
      let right = false
      let panduan = false
      let token = 'token'
      let rightName = ''
      let value1 = false
      let value2 = false
      for (let num = 0; num < 2; num++) {
        let unName = prompt('请输入用户名!')
        let passWord = prompt('请输入密码!')
        for (let i = 0; i < loginList.length; i++) {
          for (let k in loginList[i]) {
            if (loginList[i][k] === unName) {
              value1 = true
            }
            for (let k in loginList[i]) {
              if (loginList[i][k] === passWord) {
                value2 = true
              }
            }
            if (value1 && value2) {
              right = true
            }
          }
        }
        if (value1 === true && value2 === false) {
          unName = prompt('密码错误，请重新输入用户名!')
          leftName = unName
          passWord = prompt('请重新输入密码!')
          for (let i = 0; i < loginList.length; i++) {
            for (let k in loginList[i]) {
              if (loginList[i][k] === unName) {
                value1 = true
              }
              for (let k in loginList[i]) {
                if (loginList[i][k] === passWord) {
                  value2 = true
                }
              }
              if (value1 && value2) {
                right = true
              }
            }
          }
          if (
            (value1 === true && value2 === false) ||
            (value1 === false && value2 === false)
          ) {
            panduan === true
            num = 1
          }
        }
        if (right === false && num === 0) {
          while (true) {
            let tixing = +prompt(`账户不存在：
                1.注册账号
                2.直接退出`)
            if (tixing === 1) {
              let zhanghao = prompt(`账号注册：
                  请输入您的账号!`)
              let mima = prompt(`账号注册：
                  请输入您的密码!`)
              let newObj = {}
              newObj.userName = zhanghao
              newObj.password = mima
              loginList.push(newObj)
              alert('你已成功注册，直接去登录...')
              right = true
              break
            }
            if (tixing === 2) {
              panduan = true
              break
            } else {
              alert('请重新输入!')
            }
          }
        }
        if (panduan === true) {
          break
        }
        if (right === true) {
          rightName = unName
          break
        }
        if (num === 1) {
          alert('再次输错，已无机会，直接退出了！')
          break
        }
      }
      if (right === true) {
        let num = Math.floor(Math.random() * 4 + 1)
        token += num
        // console.log(token)
      }
      for (let key in userInfo) {
        if (key === token) {
          alert(`登录成功，具体用户信息：
          
          city：${userInfo[key].city}
          money：${userInfo[key].money}
          sex：${userInfo[key].sex}
          userName：${rightName}`)
        }
      }
    </script>
  </body>
</html>
